package enum_;

import java.sql.SQLOutput;

/**
 * @author DCSGO
 * @version 1.0
 */
public class EnumerationTest {
    public static void main(String[] args) {
        System.out.println(Grade2.A);
        System.out.println(Grade2.B);
        System.out.println(Grade2.C);
        System.out.println(Grade2.D);
        System.out.println(Grade2.OTHER);

        /*
         * Grade2{grade='优异', description='综测成绩在90-100'}
         * Grade2{grade='良好', description='综测成绩在80-90'}
         * Grade2{grade='合格', description='综测成绩在60-80'}
         * Grade2{grade='不合格', description='综测成绩在0-60'}
         * Grade2{grade='null', description='null'}
         */
    }

    public static void main1(String[] args) {
        System.out.println(Grade.A);
        System.out.println(Grade.B);
        System.out.println(Grade.C);
        System.out.println(Grade.D);
        /*
         * Grade{grade='优异', description='综测成绩在90-100'}
         * Grade{grade='良好', description='综测成绩在80-90'}
         * Grade{grade='合格', description='综测成绩在60-80'}
         * Grade{grade='不合格', description='综测成绩在0-60'}
         */

    }
}

//通过自定义类实现枚举
//1.正常构造一个类
//2.将构造方法 和 所有属性 设为 private 访问权限
//3.去掉 所有 set 方法 (因为枚举对象是只读的)
//4.通过 final static 修饰并在类的内部实例化几个需要的的枚举对象(对象名应为大写)
class Grade {//成绩等级
    private String grade;
    //描述
    private String description;

    private Grade(String grade, String description) {
        this.grade = grade;
        this.description = description;
    }

    public final static Grade A = new Grade("优异", "综测成绩在90-100");
    public final static Grade B = new Grade("良好", "综测成绩在80-90");
    public final static Grade C = new Grade("合格", "综测成绩在60-80");
    public final static Grade D = new Grade("不合格", "综测成绩在0-60");

    public String getGrade() {
        return grade;
    }

    public String getDescription() {
        return description;
    }

    @Override
    public String toString() {
        return "Grade{" +
                "grade='" + grade + '\'' +
                ", description='" + description + '\'' +
                '}';
    }
}

//通过 enum 关键字实现 枚举类
//1.class 替换为 enum
//2.枚举常量对象必须写在 枚举类的开头位置 且不允许添加修饰符
//3.枚举对象名(参数列表->这里会调用构造方法) 若有多个枚举对象则用 , 分隔 并以 ; 结尾
//4.枚举对象所包含的属性写在枚举对象的下面
//5.依旧不提供 set 方法
//细节说明：通过关键字 enum 实现枚举时默认会继承 Enum 类
//        通过无参构造方法类构造枚举对象时可省略 ()
enum Grade2 {
    A("优异", "综测成绩在90-100"),
    B("良好", "综测成绩在80-90"),
    C("合格", "综测成绩在60-80"),
    D("不合格", "综测成绩在0-60"),
    OTHER;//省略了无参构造方法的 ()
    String grade;
    String description;

    // private 是枚举构造函数的默认修饰符
    Grade2(String grade, String description) {
        this.grade = grade;
        this.description = description;
    }

    Grade2() {

    }

    public String getGrade() {
        return grade;
    }

    public String getDescription() {
        return description;
    }

    @Override
    public String toString() {
        return "Grade2{" +
                "grade='" + grade + '\'' +
                ", description='" + description + '\'' +
                '}';
    }
}
